// File generated from our OpenAPI spec by Stainless.

package com.metest.api.models.pet

import com.metest.api.core.MultipartField
import com.metest.api.core.http.QueryParams
import java.io.InputStream
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

internal class PetUploadImageParamsTest {

    @Test
    fun create() {
        PetUploadImageParams.builder()
            .petId(0L)
            .additionalMetadata("additionalMetadata")
            .file("some content".byteInputStream())
            .build()
    }

    @Test
    fun pathParams() {
        val params =
            PetUploadImageParams.builder().petId(0L).file("some content".byteInputStream()).build()

        assertThat(params._pathParam(0)).isEqualTo("0")
        // out-of-bound path param
        assertThat(params._pathParam(1)).isEqualTo("")
    }

    @Test
    fun queryParams() {
        val params =
            PetUploadImageParams.builder()
                .petId(0L)
                .additionalMetadata("additionalMetadata")
                .file("some content".byteInputStream())
                .build()

        val queryParams = params._queryParams()

        assertThat(queryParams)
            .isEqualTo(
                QueryParams.builder().put("additionalMetadata", "additionalMetadata").build()
            )
    }

    @Test
    fun queryParamsWithoutOptionalFields() {
        val params =
            PetUploadImageParams.builder().petId(0L).file("some content".byteInputStream()).build()

        val queryParams = params._queryParams()

        assertThat(queryParams).isEqualTo(QueryParams.builder().build())
    }

    @Test
    fun body() {
        val params =
            PetUploadImageParams.builder()
                .petId(0L)
                .additionalMetadata("additionalMetadata")
                .file("some content".byteInputStream())
                .build()

        val body = params._body()

        assertThat(body.filterValues { !it.value.isNull() })
            .usingRecursiveComparison()
            // TODO(AssertJ): Replace this and the `mapValues` below with:
            // https://github.com/assertj/assertj/issues/3165
            .withEqualsForType(
                { a, b -> a.readBytes() contentEquals b.readBytes() },
                InputStream::class.java,
            )
            .isEqualTo(
                mapOf("file" to MultipartField.of("some content".byteInputStream())).mapValues {
                    (_, field) ->
                    field.map { (it as? ByteArray)?.inputStream() ?: it }
                }
            )
    }

    @Test
    fun bodyWithoutOptionalFields() {
        val params =
            PetUploadImageParams.builder().petId(0L).file("some content".byteInputStream()).build()

        val body = params._body()

        assertThat(body.filterValues { !it.value.isNull() })
            .usingRecursiveComparison()
            // TODO(AssertJ): Replace this and the `mapValues` below with:
            // https://github.com/assertj/assertj/issues/3165
            .withEqualsForType(
                { a, b -> a.readBytes() contentEquals b.readBytes() },
                InputStream::class.java,
            )
            .isEqualTo(
                mapOf("file" to MultipartField.of("some content".byteInputStream())).mapValues {
                    (_, field) ->
                    field.map { (it as? ByteArray)?.inputStream() ?: it }
                }
            )
    }
}
